package com.dynamic.mybatis.core.metadata;

import com.dynamic.mybatis.core.enums.ReturnType;
import com.dynamic.mybatis.core.toolkit.ReturnTypeHolder;
import com.dynamic.mybatis.core.toolkit.SqlCommandTypeHolder;
import org.apache.ibatis.mapping.SqlCommandType;

import java.util.Map;

/**
 * @Description
 * 1.支持纯SQL
 *  select 1
 * 2.支持mybatis脚本SQL
 * <script> select 1 <if test='a!=null'> 1 = 1</if></script>
 * @Author xs
 * @Date 2021/11/10 15:10
 */
public class DynamicScriptMappedStatement extends DynamicMappedStatement   {

    private String resultType;//xml resultType属性
    private String resultMap;//xml resultMap属性

    public String getResultType() {
        return resultType;
    }

    public void setResultType(String resultType) {
        this.resultType = resultType;
    }

    public String getResultMap() {
        return resultMap;
    }

    public void setResultMap(String resultMap) {
        this.resultMap = resultMap;
    }

   public static    class Builder {

        private DynamicScriptMappedStatement parent;

        public Builder() {
            this.parent = new DynamicScriptMappedStatement();
        }

        public String getResultType() {
            return parent.getResultType();
        }

        public Builder setResultType(String resultType) {
            parent.resultType = resultType;
            return this;
        }

        public String getResultMap() {
            return parent.getResultMap();
        }

        public Builder setResultMap(String resultMap) {
            parent.resultMap = resultMap;
            return this;
        }

       public String getId() {
           return parent.getId();
       }

       public Builder setId(String id) {
           parent.setId(id);
           return this;
       }

       public SqlCommandType getSqlCommandType() {
           return parent.getSqlCommandType();
       }

       public Builder setSqlCommandType(SqlCommandType sqlCommandType) {
           parent.setSqlCommandType(sqlCommandType);
           return this;
       }

       public Builder setSqlCommandType(String sqlCommandType) {
           parent.setSqlCommandType(SqlCommandTypeHolder.getSqlCommandType(sqlCommandType));
           return this;
       }

       public ReturnType getReturnType() {
           return  parent.getReturnType();
       }

       public Builder setReturnType(ReturnType returnType) {
           parent.setReturnType(returnType);
           return this;
       }

       public Builder setReturnType(String returnType) {
           parent.setReturnType(ReturnTypeHolder.getReturnType(returnType));
           return this;
       }


       public String getMappedStatement() {
           return parent.getMappedStatement();
       }

       public Builder setMappedStatement(String mappedStatement) {
           parent.setMappedStatement(mappedStatement);
           return this;
       }

       public String getParameterType() {
           return parent.getParameterType();
       }

       public Builder setParameterType(String parameterType) {
           parent.setParameterType(parameterType);
           return this;
       }

       public Object getTargetDataSourceKey() {
           return parent.getTargetDataSourceKey();
       }

       public Builder setTargetDataSourceKey(Object targetDataSourceKey) {
           parent.setTargetDataSourceKey(targetDataSourceKey);
           return this;
       }

       public Object[] getDynamicDataSourceKeys() {
           return parent.getDynamicDataSourceKeys();
       }

       public Builder setDynamicDataSourceKeys(Object[] dynamicDataSourceKeys) {
           parent.setDynamicDataSourceKeys(dynamicDataSourceKeys);
           return this;
       }

       public Map<String, Object> getAttributes() {
           return parent.getAttributes();
       }

       public Builder setAttributes(Map<String, Object> attributes) {
           parent.getAttributes();
           return this;
       }
        

        public DynamicScriptMappedStatement builder(){
            return parent;
        }

    }
}